package com.oba.king.datalib.sampleproduct;

/**
 * Title:           SampleProductDetailBean
 * Description:
 * Copyright:       Copyright (c) 2003
 * Company:         King Top Limited
 * @author          Wu Liang
 * @version 1.0
 *
 * MODIFICATION HISTORY
 * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 * Date Modified        Modified By         Comments
 * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 * 26/04/2010           Wu Liang            Code Creation
 */

import java.util.List;

import com.oba.base.dao.DBDataModel;
import com.oba.base.interfaces.PageCallBack;
import com.oba.base.service.BaseBean;
import com.oba.king.datalib.productinfo.ProductInfo;

public class SampleProductDetailBean extends BaseBean<SampleProductDetail, SampleProductDetailService> {

	//用于接收数据的数据模型
	private DBDataModel sampleProductList = DBDataModel.create(new PageCallBack() {
		public void afterLoadPage(List curPage) {
			for(Object obj:curPage) {
				SampleProductDetail spd = (SampleProductDetail) obj;
				spd.setProductInfo(getService().getDao().findProductByCode(spd));
			}
		}
	});
	private DBDataModel choosePrdtList = DBDataModel.create();
	
	//用于传递页面之间的对象
	private SampleProductDetail sampleProduct;
	//用于判断是否显示弹出层
	private boolean showAddSamplePrdt = false;
	private SamplePrdtCondition samplePrdtCondition;
	private final String ADD_NEW_SAMPLE_PRDT_PATH = "/datalib/sampleProductAdd.jspx";
	private final String SHOW_SAMPLE_PRDT_PATH = "/datalib/sampleProductShow.jspx";
	 
	private String productName;
	private String productSerialId;
	private String chooseType;
	
	@Override
	public String doFind() {
//		System.out.println("Start SampleProductDetailBean doFind()>>>>");
		 sampleProductList.find(getService().getDao().buildAll());
//			System.out.println("Start SampleProductDetailBean doFind()<<<<");
		 return null;
	}

	@Override
	public void init() {
		this.doFind();
		samplePrdtCondition = new SamplePrdtCondition();		
	}

	
	/**
	 * 根据productCondition进行模糊查询
	 */
	public void srchSamplePrdtCondition(){
		sampleProductList.find(this.getService().getDao().srchSamplePrdtCondition(samplePrdtCondition));
	}
	
	/**
	 * 新增样品
	 */
	public void addNewSamplePrdt(){
//		System.out.println("Start SampleProductDetailBean addNewPrdt()>>>>");
		this.sampleProduct = new SampleProductDetail();
		this.sampleProduct.setNewBo(true);
		this.goTarget(ADD_NEW_SAMPLE_PRDT_PATH);
//		System.out.println("End SampleProductDetailBean addNewPrdt()<<<<");
	}
	
	/**
	 * 修改样品
	 */
	public void doEditSamplePrdt(){
//		System.out.println("Start ProductInfoBean doEditPrdt()>>>>");
		
		if(this.sampleProductList.isRowAvailable()){
			this.sampleProduct = (SampleProductDetail) this.sampleProductList.getRowData();
			this.goTarget(ADD_NEW_SAMPLE_PRDT_PATH);
		}
		
//		System.out.println("End ProductInfoBean doEditPrdt()<<<<");
	}
	
	/**
	 * 保存样品信息
	 */
	public void doSaveSamplePrdt(){
//		System.out.println("Start ProductInfoBean doSavePrdt()>>>>");		
		this.getService().save(this.sampleProduct);
		this.showAddSamplePrdt = false;
		this.goTarget(this.SHOW_SAMPLE_PRDT_PATH);
		this.doFind();
//		System.out.println("End ProductInfoBean doSavePrdt()<<<<");
	}
	
	/**
	 * 删除样品信息
	 */
	public void doDeleteSamplePrdt(){
//		System.out.println("Start ProductInfoBean doDeletePrdt()>>>>");
		if(this.sampleProductList.isRowAvailable()){
			this.getService().del(this.sampleProduct);
			this.goTarget(this.SHOW_SAMPLE_PRDT_PATH);
			this.doFind();
		}
//		System.out.println("End ProductInfoBean doDeletePrdt()<<<<");
	}
	
	/**
	 * 修改或新增时选择药品
	 */
	public void doChoosePrdt(){
		this.showAddSamplePrdt = true;
		this.choosePrdtList.find(this.getService().getDao().srchPrdtForChooseAll());
		
	}
	
	/**
	 * 
	 */
	public void srchByIdAndName(){
		this.choosePrdtList.find(this.getService().getDao().srchPrdtForChoose(this.productSerialId, this.productName));
	}
	
	
	/**
	 * 
	 */
	public void doChoosedPrdt(){
		//TODO 选择这个药品
		System.out.println("doChoosedPrdt");
		if(choosePrdtList.isRowAvailable()){
			ProductInfo prdtInfo = (ProductInfo)choosePrdtList.getRowData();
			sampleProduct.setProductInfo(prdtInfo);
			sampleProduct.setProductCode(prdtInfo.getProductSerialId());
			sampleProduct.setProductName(prdtInfo.getProductName());
		}
		this.showAddSamplePrdt = false;
	}
	
	/**
	 * 关闭弹出层	
	 */
	public void closeShowAddSamplePrdt(){
		this.showAddSamplePrdt = false;
	}
	
//	/**
//	 * 清除查寻
//	 */
//	public void cleanSrchButton(){
//		this.productName = "";
//		this.productSerialId = "";
//	}
	
	/**
	 * 返回显示页面
	 */
	public void doRturnShow(){
		this.goTarget(this.SHOW_SAMPLE_PRDT_PATH);
	}
	
	/**
	 * 
	 * @return
	 */
	public void cleanButton(){
		this.samplePrdtCondition = new SamplePrdtCondition();
	}
	
	public DBDataModel getSampleProductList() {
		return sampleProductList;
	}

	public void setSampleProductList(DBDataModel sampleProductList) {
		this.sampleProductList = sampleProductList;
	}

	public SampleProductDetail getSampleProduct() {
		return sampleProduct;
	}

	public void setSampleProduct(SampleProductDetail sampleProduct) {
		this.sampleProduct = sampleProduct;
	}

	public boolean getShowAddPrdt() {
		return showAddSamplePrdt;
	}

	public void setShowAddPrdt(boolean showAddPrdt) {
		this.showAddSamplePrdt = showAddPrdt;
	}

	public boolean isShowAddSamplePrdt() {
		return showAddSamplePrdt;
	}

	public void setShowAddSamplePrdt(boolean showAddSamplePrdt) {
		this.showAddSamplePrdt = showAddSamplePrdt;
	}

	public SamplePrdtCondition getSamplePrdtCondition() {
		return samplePrdtCondition;
	}

	public void setSamplePrdtCondition(SamplePrdtCondition samplePrdtCondition) {
		this.samplePrdtCondition = samplePrdtCondition;
	}

	public String getProductName() {
		return productName;
	}

	public void setProductName(String productName) {
		this.productName = productName;
	}

	public String getProductSerialId() {
		return productSerialId;
	}

	public void setProductSerialId(String productSerialId) {
		this.productSerialId = productSerialId;
	}

	public DBDataModel getChoosePrdtList() {
		return choosePrdtList;
	}

	public void setChoosePrdtList(DBDataModel choosePrdtList) {
		this.choosePrdtList = choosePrdtList;
	}

	public String getChooseType() {
		return chooseType;
	}

	public void setChooseType(String chooseType) {
		this.chooseType = chooseType;
	}

}
